<!-- 启动页面 -->
<template>
	<view class="pages">
		<image :src="img" mode="" style="width: 100%;height: 100%;"></image>
		<view class="daojishi" @click="loginOrIndex()">
			{{$t('skip')}} {{daojishi}}
		</view>
	</view>
</template>

<script>
	import getUpdate from '../../utils/mixin/upversion.js'
	export default {
		mixins:[getUpdate],
		data() {
			return {
				newUrl: 0, //0为新接口1为老接口
				img: '',
				daojishi: 3,
			}
		},
		onLoad() {
			
		},
		mounted() {
			this.getLunBao()
		},
		
		methods: {
			tolodin() {
				let that = this
				var timer = setInterval(() => {
					if (that.daojishi == 0) {
						that.daojishi = 5
						clearInterval(timer)
						that.loginOrIndex()
					}
					that.daojishi -= 1
				}, 1000)
			},
			// 获取启动页
			getLunBao() {
				uni.showLoading({
					title: this.$t('Laoding'),
				})
				this.$get('/biz/app/carouselImageList', {
					type: 0
				}, this.newUrl).then(res => {
					if(res.data.data&&res.data.data.length>0){
						// 随机取一张封面图
						var randomNum = Math.floor(Math.random() * res.data.data.length);
						this.img = res.data.data[randomNum].image
					}
					this.tolodin()
				})
			},
			loginOrIndex() {
				clearInterval(this.timer)
				// 去首页
				if(uni.getStorageSync('token')) {
					uni.switchTab({
						url:'../home/index'
					})
				} else {
					// 去登录
					uni.reLaunch({
					  url:'/pages/index/login/login'
					});
				}
			}
		}
	}
</script>

<style>
	.pages {
		position: relative;
		width: 100%;
		height: 100vh;
	}

	.daojishi {
		position: absolute;
		top: 100rpx;
		right: 60rpx;
		font-family: Montserrat;
		font-size: 28rpx;
		font-weight: 400;
		letter-spacing: 0.20000000298023224px;
		height: 50rpx;
		padding: 0 20rpx;
		line-height: 50rpx;
		background-color: rgba(0, 0, 0, 0.5);
		color:#fff ;
		border-radius: 25rpx;
	}
</style>